﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StoragePeriod.Data;
using StoragePeriod.Web.Common;
using StoragePeriod.Common;
using StoragePeriod.Model.StorageForecast;
using StoragePeriod.BLL.StorageForecast;

namespace StoragePeriod.Web.SysManage
{
    public partial class QuotaPromptEdit : System.Web.UI.Page
    {
        T_QuotaPrompt tQuotaPrompt = new T_QuotaPrompt();//指标说明操作

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["EditType"] != null && Request.QueryString["EditType"].ToString() == "Edit")
                {
                    this.LoadData();
                }
            }
        }

        //加载数据
        private void LoadData()
        {
            int PromptID = Convert.ToInt32(Request.QueryString["PromptID"].ToString());
            E_QuotaPrompt eQuotaPrompt = tQuotaPrompt.GetModel(PromptID);
            this.drop_TypeList.SelectedValue = eQuotaPrompt.RawTypeID.ToString();
            this.txt_StartNum.Text = eQuotaPrompt.StartNum.ToString();
            this.txt_EndNum.Text = eQuotaPrompt.EndNum.ToString();
            this.txt_Prompt.Text = eQuotaPrompt.Prompt;
        }

        //提交数据
        protected void btPost_Click(object sender, EventArgs e)
        {
            int QuotaID = int.Parse(Request.QueryString["QuotaID"].ToString());
            if (Request.QueryString["EditType"].ToString() == "Add")
            {
                E_QuotaPrompt eQuotaPrompt = new E_QuotaPrompt();
                eQuotaPrompt.QuotaID = QuotaID;
                eQuotaPrompt.RawTypeID = int.Parse(this.drop_TypeList.SelectedValue);
                eQuotaPrompt.StartNum = Convert.ToDecimal(this.txt_StartNum.Text.Trim());
                eQuotaPrompt.EndNum = Convert.ToDecimal(this.txt_EndNum.Text.Trim());
                eQuotaPrompt.Prompt = this.txt_Prompt.Text.Trim();
                tQuotaPrompt.Add(eQuotaPrompt);
            }
            else
            {
                int PromptID = Convert.ToInt32(Request.QueryString["PromptID"].ToString());
                E_QuotaPrompt eQuotaPrompt = tQuotaPrompt.GetModel(PromptID);
                eQuotaPrompt.RawTypeID = int.Parse(this.drop_TypeList.SelectedValue);
                eQuotaPrompt.StartNum = Convert.ToDecimal(this.txt_StartNum.Text.Trim());
                eQuotaPrompt.EndNum = Convert.ToDecimal(this.txt_EndNum.Text.Trim());
                eQuotaPrompt.Prompt = this.txt_Prompt.Text.Trim();
                tQuotaPrompt.Update(eQuotaPrompt);
            }

            ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('保存成功！');parent.window.location.href='/SysManage/QuotaPromptList.aspx?QuotaID=" + QuotaID + "';</script>");
        }
    }
}